﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.admin.templates
{
    public partial class stencil_edit : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                this.txtContent.FullPage = true;
                string dir = ChangeHope.WebPage.PageRequest.GetQueryString("dir");//地址
                string filename = ChangeHope.WebPage.PageRequest.GetQueryString("filename");//文件名
                this.returnLink.NavigateUrl = "stencil_list.aspx?name="+dir.Replace("~\\","")+"";
                if (filename != string.Empty)
                {
                    GetTemplatesContent(dir, filename);
                }
            }
        }

        /// <summary>
        /// 获取模板
        /// </summary>
        public void GetTemplatesContent(string dir,string filename)
        {
            try
            {
                ChangeHope.Common.FileHelper fh = new ChangeHope.Common.FileHelper();
                string str = fh.ReadFileContent(Server.MapPath(dir) + "\\" + filename, System.Text.Encoding.UTF8);
               this.txtContent.Value = str;
            }
            catch
            {
                this.ltlMsg.Text = "文件不存在！";
                this.pnlMsg.Visible = true;
                this.pnlMsg.CssClass = "actionOk";
            }
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            string dir = ChangeHope.WebPage.PageRequest.GetQueryString("dir");//地址
            string filename = ChangeHope.WebPage.PageRequest.GetQueryString("filename");//文件名
            string Content = this.txtContent.Value;
            if (Content!=string.Empty)
            {
                ChangeHope.Common.FileHelper fh = new ChangeHope.Common.FileHelper();
                bool bl = fh.WriteFileContent(Server.MapPath(dir) + "\\" + filename, Content, true);
                if (bl)
                {
                    this.ltlMsg.Text = "操作成功,模板以保存.";
                    this.pnlMsg.Visible = true;
                    this.pnlMsg.CssClass = "actionOk";
                }
            }
        }
    }
}
